<%@ page language="java" import="com.beans.AdminInfo" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%AdminInfo admin=(AdminInfo)session.getAttribute("session_admin");
	request.setAttribute("admin",admin);%> 
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>"> 
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
</head>

<body>
<div class ="div_title">
	 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>用户密码修改</span></div>
</div>
 <table class="edit_table" >
 		<tr>
		 	<td class="td_info">用户账号:</td>	
		 	<td class="td_input_short"> 
		 		<input type="text" class="txtbox" id="adminName" name="adminName"  value="${admin.adminName}" disabled="disabled"/> 
		 	</td>   
		 	<td>
		 		<label class="validate_info" id="adminName_msg"></label>
		 	</td> 
 		</tr>
 		<form>
 		<tr>
			<td class="td_info">原密码:</td>	
			<td >
				<input type="password"  class="txtbox"  name="old_password"  id="old_password" />
			</td> 
			
			<td><label class="validate_info" id="old_password_msg">请输入原来的密码</label></td>	
 		</tr>
		<tr>
			<td class="td_info">新密码:</td>	
			<td class="td_input_short">
				<input type="password"  class="txtbox"  name="password" id="password" onblur="validatePassword(this);" onfocus="showInfo('请输入6-20位的,字母和数字',this);"/>
			</td> 
			<td><div id="pwddiv"><label class="validate_info" id="password_msg">数字或英文,6-20位</label></div></td>
 		</tr>
		<tr>
			<td class="td_info">重复密码:</td>	
			<td class="td_input_short"><input type="password" class="txtbox" id="pwdconfirm" name="pwdconfirm" onfocus="showInfo('所填内容需与密码相同',this);" onblur="verifyPasswordRepeatedly(this);"/> 
			</td>
			<td><label  class="validate_info"  id="pwdconfirm_msg">请输入重复的密码</label></td>	
 		</tr>
 		<tr>
 			<td class="td_info"> </td>	
 			<td> 
 			<input class="form_btn" type="button" value="修改" id="submit"/>
 			<input type="reset"  class="form_btn" value="重置" /> </td>	
 			<td>
 				<label id="result_msg" class="result_msg">${msg}</label>
 			</td>	
 		</tr>
 		</form>
</table>
<script type="text/javascript" src="js/regin.js" ></script>
<script >
function validate() {
	var result = 0;
	if ($s("old_password").value === "") {
        result = result + showError("密码不能为空", $s("old_password"));
    }
	else if ($('#old_password_msg')[0].style.color == "red") {
        result = result + 1;
    }
	if ($s("password").value === "") {
        result = result + showError("密码不能为空", $s("password"));
    }
	else if ($('#password_msg')[0].style.color == "red") {
        result = result + 1;
    }

    if ($s("pwdconfirm").value === "") {
        result = result + showError("重复密码不能为空", $s("pwdconfirm"));
    }
    else if ($('#pwdconfirm_msg')[0].style.color == "red") {
        result = result + 1;
    }
    
    if (result === 0) {
        result = confirm("确定要提交吗");
        return result;
    } else {
        return false;
    }
}
$(function() {
	$("#submit").click(function () {
		if (validate()) {
			$.ajax({
				 url:"AdminServlet.do",
				 type:"POST",
				 data:{flag:"pswedit",id:'${admin.id}',oldpsw:$("#old_password").val(),psw:$("#password").val()},
				 success:function(data){
					 $("#result_msg").html(data);
				 } 
			 }); 
		}
		
	});
})
</script>
</body>
</html>